package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.sql.SqlUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.domain.dto.SelectDto;
import com.ruoyi.system.domain.vo.SelectVo;
import com.ruoyi.system.service.IBizSelectCommonService;
import com.ruoyi.system.service.impl.BizSelectCommonServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通用返回选择器组件的接口
 */
@RestController
@RequestMapping("/common")
public class BizSelectCommonController {

    @Autowired
    private IBizSelectCommonService bizSelectCommonService;

    @GetMapping("/mapList")
    public AjaxResult mapList(SelectDto dto) {
        try {
            if (StringUtils.isEmpty(dto.getValueName())
                    || StringUtils.isEmpty(dto.getTableName())
                    || StringUtils.isEmpty(dto.getKeyName())) {

                return AjaxResult.error("参数不能为空");
            } else {
                List<SelectVo> all = bizSelectCommonService.findAll(dto);
                return AjaxResult.success(all);
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }

    }
}
